<template>
  <info :id="id" type="seek" :title="type === 1 ? '车找人' : '人找车'" :loadDataMethod="loadData"></info>
</template>

<script>
import Info from '@c/page/Info'
export default {
  components: {
    Info
  },

  data (){
    return {
      id: '',
      type: 1     // 1：找人，2：找车
    }
  },

  beforeMount (){
    this.id = this.$route.query.id
    this.type = this.$route.query.type || this.type
  },

  methods: {
    // 加载数据
    loadData (){
      return new Promise((resolve, reject) =>{
        _api('seek/getById', {
          level: '0,2,3',
          id: this.id
        }).then(data =>{
          var {user, tel, is_collect} = data

          if(this.type === 1){
            var info = [
              {
                title: '班次',
                value: data.shift_type_str,
                showy: true
              }, {
                title: '交班位置',
                value: data.exchange_address
              }, {
                title: '班费',
                value: data.expense === '0.00' ? '面议' : data.expense + '元'
              }, {
                title: '交班时间',
                value: data.exchange_start_time.replace(/:00$/, '') + ' - ' + 
                       data.exchange_end_time.replace(/:00$/, '')
              }, {
                title: '备注',
                value: data.remark || '这个人很懒，什么都没有写'
              }            
            ]
          }else{
            var info = [ 
               {
                title: '班费',
                value: data.expense === '0.00' ? '面议' : data.expense + '元',
                showy: true
              },{
                title: '交班位置',
                value: data.exchange_address
              }, {
                title: '交班时间',
                value: data.exchange_start_time.replace(/:00$/, '') + ' - ' + 
                       data.exchange_end_time.replace(/:00$/, '')
              }, {
                title: '备注',
                value: data.remark || '这个人很懒，什么都没有写'
              }            
            ]            
          }

          var infoCard = {
            avatar: user.avatar,
            userName: user.nick_name,
            isTransfer: data.is_transfer,
            info
          }

          console.log(is_collect)
          resolve({ tel, infoCard, collected: !!parseInt(is_collect) })
        }).catch(reject)
      })
    },
  }
}
</script>

<style lang="less" scoped>

</style>